package com.xoa.service.workflow.flowDestroy.imp;

import com.xoa.dao.workflow.FlowDestroyMapper;
import com.xoa.model.workflow.FlowRun;
import com.xoa.service.workflow.flowDestroy.FlowDestroy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class FlowDestroyImp implements FlowDestroy {

    @Resource
    private FlowDestroyMapper flowDestroyMapper;

   /* @Override
    public List<FlowRun> getDeleteList() {

        return flowDestroyMapper.getFlowRunList();
    }*/

   /* @Override
    public int destroyFlowRun(int runId) {
        System.out.println("jin  ru  service:destroyFlowRun(int runId)="+runId);
        int count=flowDestroyMapper.deleteFlowRunByRunId(runId);
        System.out.println("service  ying  xiang hang  shu:"+count);
        return count ;
    }*/
/**
* @创建作者:李然  Lr
* @方法描述：flowrun销毁数据
* @创建时间：16:31 2018/7/5

**/
    @Override
    public int destroyFlowRunByRunIdArray(String[] runIdArray) {

        return flowDestroyMapper.deleteFlowRunByRunIdArray(runIdArray);
    }



    /**
     * @创建作者:李然  Lr
     * @方法描述：flowrunprcs表销毁数据
     * @创建时间：16:31 2018/7/5

     **/
    @Override
    public int destroyFlowRunPrcsByRunIdArray(String[] runIdArray) {
        return flowDestroyMapper.deleteFlowRunPrcsByRunIdArray(runIdArray);
    }

    @Override
    public int restoreFlowRunByRunIdArray(String[] runIdArray) {
        return flowDestroyMapper.updateFlowRunByRunIdArray(runIdArray);
    }

    /**
    * @创建作者:李然  Lr
    * @方法描述：通过runId数组查找对应的flowId
    * @创建时间：14:29 2018/7/5

    **/
    @Override
    public List<Integer> getFlowIdByrunIdArryInt(String[] runIdArrayInt) {

        return flowDestroyMapper.getFlowIdByRunIdArray(runIdArrayInt);
    }
/**
* @创建作者:李然  Lr
* @方法描述：单独删除flow_data表里的数据
* @创建时间：15:03 2018/7/5

**/
    @Override
    public int destroyFlowDataNum(String runId, String flowId) {
        return flowDestroyMapper.deleteFlowDataNum(runId,flowId);
    }
/**
* @创建作者:李然  Lr
* @方法描述：全部销毁
* @创建时间：17:48 2018/7/5

**/
    @Override
    public int allDestroy() {
        int count=0;//影响行数
        //获得所有已被删除的runId
        List<String> runIdLsit=flowDestroyMapper.getFlowRunList();
        String[] runIdArray=new String[runIdLsit.size()];
        for(int i=0;i<runIdArray.length;i++){
            //循环放入int数组中
            runIdArray[i]=runIdLsit.get(i);
        }
        count=count+flowDestroyMapper.deleteFlowRunByRunIdArray(runIdArray);
        count=count+ flowDestroyMapper.deleteFlowRunPrcsByRunIdArray(runIdArray);
        List<Integer> flowIdList=flowDestroyMapper.getFlowIdByRunIdArray(runIdArray);
        String tableName="flow_data_";
        for(int j=0;j<flowIdList.size();j++){

            count=count+flowDestroyMapper.deleteFlowDataNum(runIdArray[j],tableName+flowIdList.get(j));
        }

        return count;
    }

    /**
    * @创建作者:李然  Lr
    * @方法描述：全部还原功能
    * @创建时间：18:24 2018/7/5

    **/
    @Override
    public int allRestore() {
        return flowDestroyMapper.updateFlowRunDelFalg();
    }
    /**
    * @创建作者:李然  Lr
    * @方法描述：通过多条件查询FlowRun中的数据
    * @创建时间：10:06 2018/7/6

    **/
    @Override
    public List<FlowRun> query(Map maps) {
        //获取查询结果
        List<FlowRun> flowRunList=flowDestroyMapper.selectFlowRunListBycondition(maps);
        return flowRunList;
    }
}
